In [2]:
import pandas as pd
import seaborn as sns
In [3]:
df = sns.load_dataset("titanic")
df.head()
Out[3]:
survived | pclass | sex | age | sibsp | parch | fare | embarked | class | who | adult_male | deck | embark_town | alive | alone | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 0 | 3 | male | 22.0 | 1 | 0 | 7.2500 | S | Third | man | True | NaN | Southampton | no | False |
1 | 1 | 1 | female | 38.0 | 1 | 0 | 71.2833 | C | First | woman | False | C | Cherbourg | yes | False |
2 | 1 | 3 | female | 26.0 | 0 | 0 | 7.9250 | S | Third | woman | False | NaN | Southampton | yes | True |
3 | 1 | 1 | female | 35.0 | 1 | 0 | 53.1000 | S | First | woman | False | C | Southampton | yes | False |
4 | 0 | 3 | male | 35.0 | 0 | 0 | 8.0500 | S | Third | man | True | NaN | Southampton | no | True |
In [41]:
sns.barplot(x = "sex", y= "age",hue = "survived" ,data = df)
Out[41]:
<Axes: xlabel='sex', ylabel='age'>
In [5]:
sns.stripplot(x="class", y= "age",hue = "sex", data = df)
Out[5]:
<Axes: xlabel='class', ylabel='age'>
In [23]:
# x = pd.crosstab(columns=[df["class"],df["survived"],df["age"]] , index=df["sex"]) ## to draw the pivot table
x=pd.crosstab(columns=df["class"],index=df["survived"])
In [24]:
x
Out[24]:
class | First | Second | Third |
---|---|---|---|
survived | |||
0 | 80 | 97 | 372 |
1 | 136 | 87 | 119 |
In [25]:
sns.heatmap(x,annot= True, fmt = ".1f")
Out[25]:
<Axes: xlabel='class', ylabel='survived'>
In [26]:
df2 = sns.load_dataset("iris")
df2.head()
Out[26]:
sepal_length | sepal_width | petal_length | petal_width | species | |
---|---|---|---|---|---|
0 | 5.1 | 3.5 | 1.4 | 0.2 | setosa |
1 | 4.9 | 3.0 | 1.4 | 0.2 | setosa |
2 | 4.7 | 3.2 | 1.3 | 0.2 | setosa |
3 | 4.6 | 3.1 | 1.5 | 0.2 | setosa |
4 | 5.0 | 3.6 | 1.4 | 0.2 | setosa |
In [27]:
df2.head(10).plot(kind = "bar")
Out[27]:
<Axes: >
In [28]:
df2.head(10).plot(kind = "bar", stacked = True)
Out[28]:
<Axes: >
In [31]:
sns.pairplot(df)
# univariate makes histogram
# bivariate makes scatterplot
Out[31]:
<seaborn.axisgrid.PairGrid at 0x184cf032d10>
In [34]:
sns.pairplot(df2)
# univariate makes histogram
# bivariate makes scatterplot
Out[34]:
<seaborn.axisgrid.PairGrid at 0x184d48ee390>
In [ ]: